﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Windows.Devices.Sensors;
using NetduinoRobot.Common;
using log4net;

namespace ControlCenter.Sensors
{
    class DeviceReader
    {
        public float XValue { get; set; }
        public float YValue { get; set; }
        public float ZValue { get; set; }

        private Inclinometer _inclino;
        private Filter _xFilter;
        private Filter _yFilter;
        private ILog _log = null;

        public DeviceReader(): this(Filter.FilterType.None)
        {
        }

        public DeviceReader(Filter.FilterType filter)
        {
            _inclino = Inclinometer.GetDefault();
            _xFilter = new Filter(filter);
            _xFilter.FilterLength = 3;
            _yFilter = new Filter(filter);
            _yFilter.FilterLength = 3;
            _log = LogManager.GetLogger("Sensor");
            _log.Debug("X; Y; X-Filter; Y-Filter");
        }

        public void DoReading()
        {
            InclinometerReading reading = _inclino.GetCurrentReading();
            XValue = _xFilter.DoFiltering(reading.RollDegrees);
            YValue = _yFilter.DoFiltering(reading.PitchDegrees);
            _log.Debug(reading.RollDegrees + "; " + reading.PitchDegrees+ "; "+ XValue + "; " + YValue);
            ZValue = reading.YawDegrees;
        }
    }
}